//
//  AppDelegate.m
//  01-UIView、UIWindow
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "UIView+Frame.h"

@interface AppDelegate ()<UITextFieldDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
#if 0
    {
//    程序的组成结构
//    1.main.m 主要实现了程序的正常运行\
//    2.AppDelegate程序的执行者 签订了UIApplicationDelegate()
//    注意:AppDelegate就是个普通的类,只不过签订了协议,才有了那么多方法
//    3.ViewController 视图控制器, 主要负责视图管理 看的见 摸得到
//    4.Main.sb(视图管理) LaunchScreen.sb(负责启动页) 可视化管理(Xcode 7 以前叫LaunchScreen.xib)
//    5.Assets.xcassets 主要管理图片素材(Xcode 7 以前叫Image.xcassets)
//    6.Info.plist(工程配置文件)
//    模拟器
//    command + 1~5 改变模拟器大小
//    command + ←/→ 横/竖切换
    
    /**UI概述*/
//    1 UIWindow(程序中只有一个主UIWindow)
//      1> 取消程序的可视化入口 , Main.sb
//      2>创建主window对象
//      3>创建主window,使其大小与屏幕一样
//    UIScreen 系统屏幕类
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//   2.给你创建的窗口填颜色, UIColor 系统的颜色类
    _window.backgroundColor = [UIColor whiteColor];
//   3.让window 显示并成为主窗口
    [_window makeKeyAndVisible];
//    4.设置window的主窗口
//    Xcode 7 以后必须设置rootViewController,否则,在该方法结束时,会崩溃
    _window.rootViewController = [[UIViewController alloc]init];
//    3>UIWindow 继承与UIView
//    2.UIView (与NSObject 相似 , 是UI阶段的根类, 大部分UI控件继承于UIView)
//    学习新类
//      1>需要新类包含哪些初始方法
//      2>包含哪些行为(方法)和特征(属性)
//    创建UIView
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 100, 250)];
//    设置背景色
    view.backgroundColor = [UIColor greenColor];
//    添加的window上
    [_window addSubview:view];
//    遇到UIView的子类,都可以用以上方式创建和显示
//    UIView 在屏幕中显示为矩形
//    iOS系统坐标系
//    1.与数学中的坐标系不同, y的正方向是向下的
//    2.原点是屏幕的左上角
//    frame bounds center(UIView 的属性)
//    1.frame (x , y ,width , height)视图在其父视图上的位置
//    2.bounds (x, y, width , height)视图本身的坐标系(0, 0,width, height)
//           bounds x ,y 修改本身坐标系影响它的子视图
//            bounds width , height修改的是本身的大小,会以中心点收缩/扩张
//              bounds的改变不会改变该视图的位置
//    3.center中心点 (改变中心点)
    view.center = CGPointMake(50, 50);
//    bounds对视图的影响测试
//    bounds
//    CGRect 和CGPoint
    view.frame = CGRectMake(10, 10, 80, 80);
    NSLog(@"改变前的bounds:%@", NSStringFromCGRect(view.frame));
    NSLog(@"该变前的center:%@", NSStringFromCGPoint(view.center));
    view.bounds = CGRectMake(0, 0, 100, 100);
    NSLog(@"改变后的bounds:%@", NSStringFromCGRect(view.frame));
    NSLog(@"改变后的center:%@", NSStringFromCGPoint(view.center));
//     bounds的x,y影响姿势图的frame, 改变坐标系
    UIView *subView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
    subView.backgroundColor = [UIColor yellowColor];
    [view addSubview:subView];
//    该变绿色viewd 的大小,with变成100
    view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, 100, view.frame.size.height);
//    view.frame get 方法
//    frame.size 结构体
//     OC 和 C 的内容结合, 是一个常量
//    view.frame.size.width = 100; //这是错误的写法
    CGRect rect = view.frame;
    rect.size.width = 100;
    view.frame = rect;
    
    view.ml_width = 100;
    }
#endif
    
//    UIView 的基本属性
     self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
      _window.rootViewController = [[UIViewController alloc]init];
    UIView *testView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
//    添加
    [_window addSubview:testView];
//    移除
//    [testView removeFromSuperview];
//   1 设置背景颜色
    testView.backgroundColor = [UIColor blueColor];
//   2 alpha 透明度 0.0 ~1.0 默认值1.0
    testView.alpha = 0.1;
//   3 tag 标记(编码) 默认为0
    testView.tag = 1000;
//    根据teg获取到对应得View_kindof
    UIView *view1 = [_window viewWithTag:1000];
//    4 subViews 子视图们
   UIView *arrayView = [_window.subviews objectAtIndex:0];
    NSLog(@"%@", arrayView);
//    5 superView 父视图
//    testView.superview;
//    6 hidden 隐藏/显示
    testView.hidden = YES;
//    视图层级
    UIView *firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
    firstView.backgroundColor = [UIColor redColor];
    UIView *secondView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 80, 80)];
    secondView.backgroundColor = [UIColor yellowColor];
    UIView *lastView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 80, 80)];
    lastView.backgroundColor = [UIColor blueColor];
    
//     addSubview (添加视图)
    [_window addSubview:firstView];
    
//    insertSubview: atIndex:(插入视图制定下标)
    NSLog(@"%@", _window.subviews);
    [_window insertSubview:secondView atIndex:2];
//    insertSubview: aboveSubview:(插入视图,到指定视图的上面)
    [_window insertSubview:lastView aboveSubview:secondView];
//     insertSubview: belowSubview:(插入视图,到指定视图的下面)
    [_window insertSubview:lastView belowSubview:secondView];
//    UILabel
//    如果类没有自己的初始化方法,则使用父类
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 300, 100)];
    label.backgroundColor = [UIColor blackColor];
    [_window addSubview:label];
    
//    label的属性
//    1.text 文本
    label.text = @"我是王煌 , 我很濉爱好发给你赶快拉及配件hi就'烦死;立fwfiivriiajviewfisdiivn3knfisdvngi4nvisdnviwnvisngigvisnbigvnsaibnwavnarignivnrignisnrbrwigib34tgsrjbigbnaibniznbrinbrie帮你;ribnlak/dnf;borga;p今年ev而跑步机进破解诶怕就不能拍就";
//    2.textColor 文本颜色
    label.textColor = [UIColor lightGrayColor];
//    3.font 默认值17
    label.font = [UIFont systemFontOfSize:28];
//    大小
    label.font = [UIFont boldSystemFontOfSize:15];
//    textAlignment 对其方式 (默认方式 NSTextAlignmentLeft)
//    left rigth Center
    label.textAlignment = NSTextAlignmentCenter;
//   5 numberOfLines 默认为1行
//      不确定的给0;
    label.numberOfLines = 4;
//  6   lineBreakMode换行模式...位置
    label.lineBreakMode = NSLineBreakByTruncatingMiddle;
    
//   7 设置阴影
    label.shadowColor = [UIColor blackColor];
    label.shadowOffset = CGSizeMake(-2, 0);
//    UIButton
//  UIButtonTypeSystem 系统的按钮类型
    UIButton * button  = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor purpleColor];
    
    [_window addSubview:button];
    button.ml_x = 0;
    button.ml_y = 300;
    button.ml_width = 100;
    button.ml_height = 100;
//    给button 添加事件
    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
//    给Button添加文字s
    [button setTitle:@"dd1`" forState:UIControlStateNormal];
//     修改颜色字体
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// 添加图片
    
    UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    imageButton.frame = CGRectMake(20, 490, 390, 50);
    imageButton.backgroundColor = [UIColor greenColor];
    [imageButton setTitle:@"登录" forState:UIControlStateNormal];
    [imageButton setImage:[UIImage imageNamed:@"GreenMe2x.png"] forState:UIControlStateNormal];
    [_window addSubview:imageButton];

    
//    UItextField
    UITextField *texfild = [[UITextField alloc]initWithFrame:CGRectMake(100,100 , 200, 300)];
    

    texfild.backgroundColor = [UIColor redColor];
    [_window addSubview:texfild];
//    1 给输入框服初值
    texfild.text = @"文字";
//    2文字颜色
    texfild.textColor = [UIColor whiteColor];
//    3
//    UITextBorderStyleNone 无
//    UITextBorderStyleLine 边缘线;
//    UITextBorderStyleBezel 
//    UITextBorderStyleRoundedRect 边缘圆角
    texfild.borderStyle = UITextBorderStyleBezel;
//    4 placeholder 占位字符
//    当text不为空的时候placeholder不显示
    texfild.placeholder = @"shuru wenzi ";
//    5 clearsOnBeginEditing 开始编辑的英文
    texfild.clearsOnBeginEditing = YES;
//    command + k
    texfild.delegate = self;
    
    
    
    
    
    
    
    
    
    return YES;
}

- (void)buttonClicked{
//    结束编辑
    [_window endEditing:YES];
    NSLog(@"beisdiaw");

}
// 开始编辑前 , 判段能否编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    
// return Yes 可以编辑
// return No 不可以编辑
    return YES;
}
// 已经开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
}
// 判断是否结束编辑
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    
    
    
    return YES;
}
// 已经结束编辑
- (void)textFieldDidEndEditing:(UITextField *)textField{
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//    处理点击return需要进行的操作
//    回收键盘
    [textField endEditing:YES];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
